import { INCREMENT, DECREMENT } from '../const/counter.const';
import { decrement, increment } from '../actions/counter.actions';
import { handleActions as createReducer, handleActions } from 'redux-actions';

const initialState = {
  count: 0
};

// export default (state = initialState, action) => {
//   switch(action.type) {
//     case INCREMENT: 
//       return {
//         ...state,
//         count: state.count + action.payload
//       };
//     case DECREMENT: 
//       return {
//         ...state,
//         count: state.count - action.payload
//       };
//     default: 
//       return state;
//   }
//   return state;
// }

const handleIncrement = (state, action) => ({count: state.count + action.payload});
const handleDecrement = (state, action) => ({count: state.count - action.payload});

export default createReducer({
  [increment]: handleIncrement,
  [decrement]: handleDecrement
}, initialState);